﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="FL.Web.BackEnd.DataGrid" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../SFramework/boot.js"></script>


    <style type="text/css">
        body {
            padding-left: 0px;
            font-size: 13px;
        }

        h1 {
            font-size: 20px;
            font-family: Verdana;
        }

        h4 {
            font-size: 16px;
            margin-top: 25px;
            margin-bottom: 10px;
        }

        .description {
            padding-bottom: 30px;
            font-family: Verdana;
        }

        .description h3 {
            color: #CC0000;
            font-size: 16px;
            margin: 0 30px 10px 0px;
            padding: 45px 0 8px;
            /*background:url(titleback.png) no-repeat scroll left bottom transparent*/
            border-bottom: solid 1px #888;
        }

        body {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>

    <!--引入皮肤样式-->
    <link href="../../SFramework/miniui/themes/blue/skin.css" rel="stylesheet" />

</head>

<body>

    <div class="mini-splitter" style="width: 100%; height: 100%;">
        <div size="240" showcollapsebutton="true">
            <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                <span style="padding-left: 5px;">名称：</span>
                <input class="mini-textbox" />
                <a class="mini-button" iconcls="icon-search" plain="true">查找</a>
            </div>
            <div class="mini-fit">
                <ul id="tree1" class="mini-tree" url="../data/jsondata.aspx?entity=<%=GetStringFromQueryString("masterentity","t_base_department") %>&type=1" style="width: 100%;"
                    showtreeicon="true" textfield="name" idfield="id" parentfield="parent_id" resultastree="false">
                </ul>
            </div>
        </div>
        <div showcollapsebutton="true">
            <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">

                <a class="mini-button" iconcls="icon-add" plain="true" onclick="addRow()">新增</a>
                <a class="mini-button" iconcls="icon-remove" plain="true" onclick="removeRow()">删除</a>
                <span class="separator"></span>
                <a class="mini-button" iconcls="icon-save" plain="true" onclick="saveData()">保存</a>
            </div>
            <div class="mini-fit">
                <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;"
                    borderstyle="border:0;"
                    url="../data/jsondata.aspx?entity=<%=EntityName%>&type=1"
                    showfilterrow="true" allowcellselect="true" allowcelledit="true">
                    <div property="columns">
                        <%=DataFields %>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        mini.parse();

        var tree = mini.get("tree1");
        var grid = mini.get("grid1");

        tree.on("nodeselect", function (e) {

            if (e.isLeaf) {
                grid.load({ condition : "dictionary_id='"+e.node.id+"'" });
            } else {
                grid.setData([]);
                grid.setTotalCount(0);
            }
        });
        //////////////////////////////////////////////
        var Genders = [{ id: 1, text: '男' }, { id: 2, text: '女' }];
        function onGenderRenderer(e) {
            for (var i = 0, l = Genders.length; i < l; i++) {
                var g = Genders[i];
                if (g.id == e.value) return g.text;
            }
            return "";
        }
        function onNameFilterChanged(e) {
            var textbox = e.sender;
            var key = textbox.getValue();

            var node = tree.getSelectedNode();
            if (node) {
                grid.load({ dept_id: node.id, key: key });
            }
        }
        function addRow() {
            var node = tree.getSelectedNode();
            if (node) {
                var newRow = { name: "New Row" };
                newRow.dept_id = node.id;
                grid.addRow(newRow, 0);
            }
        }
        function removeRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                grid.removeRows(rows, true);
            }
        }
        function saveData() {
            var data = grid.getChanges();
            var json = mini.encode(data);
            grid.loading("保存中，请稍后......");
            $.ajax({
                url: "../data/AjaxService.aspx?method=SaveEmployees",
                data: { data: json },
                type: "post",
                success: function (text) {
                    grid.reload();
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                }
            });
        }
    </script>
</body>

</html>
